package com.tedu;

import com.tedu.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;


@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/add")
    public void add(User user) throws Exception{
        System.out.println(user);
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/jdbctest";
        String username ="root";
        String password = "root";
        Connection conn =DriverManager.getConnection(url,username,password);
        String sql = "insert into user values( ?,?,?)";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setInt(1,user.getId());
        ps.setString(2,user.getName());
        ps.setString(3,user.getPwd());
        int rows = ps.executeUpdate();
        System.out.println(rows);
        System.out.println("插入成功");
    }
}
